`
https://leetcode.cn/problems/find-the-maximum-number-of-marked-indices/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var maxNumOfMarkedIndices = function (nums) {
  const n = nums.length
  nums.sort((a, b) => a - b)

  // 是否可以标记 k 个
  const check = (k) => {
    for (let i = 0; i < k; i++) {
      // 如果对于所有的 0 <= i < k，都满足 2 * nums[i] <= nums[n − k + i]，那么就可以从 nums 中选出 k 个能匹配的数对
      if (nums[i] * 2 > nums[n - k + i]) {
        return false
      }
    }
    return true
  }

  let left = 0, right = Math.floor(n / 2) + 1
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (check(mid)) {
      left = mid
    } else {
      right = mid
    }
  }
  // 匹配 left 对，有 left * 2 个标记
  return left * 2
};